package com.xhj.mybatis.mapper;

import com.xhj.mybatis.annotations.Delete;
import com.xhj.mybatis.annotations.Insert;
import com.xhj.mybatis.annotations.Select;
import com.xhj.mybatis.annotations.Update;
import com.xhj.mybatis.entity.User;

import java.util.List;
import java.util.Map;

/**
 * UserMapperByAnnotation
 *
 * @author XJks
 * @description 用户实体类的Mapper接口，使用注解方式定义SQL语句。
 */
public interface UserMapperByAnnotation {

    @Select("SELECT * FROM user")
    @Select(value = "SELECT id FROM user", databaseId = "DatabaseId1")
    @Select(value = "SELECT username FROM user", databaseId = "DatabaseId2")
    List<User> selectAll();

    // -------------------------------- selectByUsername --------------------------------
    @Select("SELECT * FROM user WHERE username = #{username}")
    User selectOneByUsername(String username);

    @Select("SELECT * FROM user WHERE username = #{username}")
    List<User> selectListByUsername(String username);

    // -------------------------------- insertOne --------------------------------
    @Insert("INSERT INTO user (id, username, status, booleanColumn, byteColumn, shortColumn, longColumn, floatColumn, doubleColumn, stringColumn)\n" +
            "VALUES (#{id}, #{username}, #{status}, #{booleanColumn}, #{byteColumn}, #{shortColumn}, #{longColumn}, #{floatColumn}, #{doubleColumn}, #{stringColumn})")
    int insertOneBySeparateParameters(Long id, String username, Integer status, Boolean booleanColumn, Byte byteColumn, Short shortColumn, Long longColumn, Float floatColumn, Double doubleColumn, String stringColumn);

    @Insert("INSERT INTO user (id, username, status, booleanColumn, byteColumn, shortColumn, longColumn, floatColumn, doubleColumn, stringColumn)\n" +
            "VALUES (#{id}, #{username}, #{status}, #{booleanColumn}, #{byteColumn}, #{shortColumn}, #{longColumn}, #{floatColumn}, #{doubleColumn}, #{stringColumn})")
    int insertOneByEntityParameter(User user);

    @Insert("INSERT INTO user (id, username, status, booleanColumn, byteColumn, shortColumn, longColumn, floatColumn, doubleColumn, stringColumn)\n" +
            "VALUES (#{id}, #{username}, #{status}, #{booleanColumn}, #{byteColumn}, #{shortColumn}, #{longColumn}, #{floatColumn}, #{doubleColumn}, #{stringColumn})")
    int insertOneByMapParameter(Map<String, Object> params);

    // -------------------------------- deleteAll --------------------------------
    @Delete("DELETE FROM user")
    int deleteAll();

    // -------------------------------- deleteListByUsername --------------------------------
    @Delete("DELETE FROM user WHERE username = #{username}")
    void deleteListByUsernameForVoidReturnType(String username);

    @Delete("DELETE FROM user WHERE username = #{username}")
    int deleteListByUsernameForIntegerReturnType(String username);

    @Delete("DELETE FROM user WHERE username = #{username}")
    long deleteListByUsernameForLongReturnType(String username);

    @Delete("DELETE FROM user WHERE username = #{username}")
    boolean deleteListByUsernameForBooleanReturnType(String username);

    // -------------------------------- updateUsernameById --------------------------------
    @Update("UPDATE user SET username = #{username} WHERE id = #{id}")
    int updateUsernameByIdAndSeparateParameters(Long id, String username);

    @Update("UPDATE user SET username = #{username} WHERE id = #{id}")
    int updateUsernameByIdAndEntityParameter(User user);

    @Update("UPDATE user SET username = #{username} WHERE id = #{id}")
    int updateUsernameByIdAndMapParameter(Map<String, Object> params);
}
